#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@author: lyndon
@time Created on 2019/2/20 15:10
@desc
"""
import json


class BaseTask:
    def __init__(self, *args, **kwargs):
        """
        :param args: id, name
        :param kwargs: others
        """
        self.task_id = args[0]
        self.task_name = args[1]
        self.task_info = {}
        if isinstance(kwargs, dict):
            self.task_info = kwargs

    def __repr__(self):
        """
        lambda obj: obj.__dict__          会将任意的对象，转换成字典的方式
        sort_keys=True                    会按照字典中的键来按照ASCII方式来排序
        indent=4                          会按照键值对以间隔4来直观的显示
        :return: json
        """
        return json.dumps(self, default=lambda obj: obj.__dict__, sort_keys=True, indent=4)

    def task_run(self):
        print(self.task_id, 'Your task is running!')
        return '0', self.task_id, self.task_name


if __name__ == '__main__':
    # t = ('id', 'name')
    bt = BaseTask('123', 'taskname', size='456', weight=500)
    # taskinfo = {'id': '123', 'name': 'taskname'}
    # bt = BaseTask(taskinfo)
    print('-----------------------')
    print(bt)

